<template>
  <el-radio-group v-model="radio" @change="change"><slot></slot></el-radio-group>
</template>
<script>
export default {
  name: 'QPRadioGroup',
  props: {
    rowData: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  data() {
    return {
      radio: ''
    }
  },
  mounted() {
    // 回显
    setTimeout(() => {
      if (this.rowData.chooseOptions) {
        this.radio = this.rowData.chooseOptions
      }
    })
  },
  methods: {
    change(val) {
      // 前面两行代码是为了获取选项的描述和得分传给后台
      const optionList = JSON.parse(this.rowData.options)
      const currentSelectItem = optionList.filter(item => {
        return item.option === val
      })
      // 接口传参格式
      let param = {
        contentId: this.rowData.id,
        titleType: this.rowData.titleType,
        options: this.radio,
        optionsDesc: currentSelectItem[0].des,
        optionsScore: currentSelectItem[0].score
      }
      this.$emit('radioChange', param)
    }
  }
}
</script>
